{% extends 'index.html' %}
{% block sidebar %}
    {% include 'include/backend/sidebar.html' %}
{% endblock %}

{% block content %}
    <h3 class="page-header">
        已创建的项目
        <a href="/backend/Project/add/" class="pull-right" >Add</a>
    </h3>
    <div class="table-responsive">
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>项目名</th>
                    <th>项目描述</th>
                    <th></th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
            {% for row in query_set %}
                <tr nid="{{ row.id }}">
                    <td><a href="{% url 'project_manage' row.id %}">{{ row.name }}</a></td>
                    <td>{{ row.description }}</td>
                    <td><a class="btn btn-info" style="padding: 5px 10px; font-size:10px" href="{% url 'project_change' row.id %} ">修改</a></td>
                    <td><button class="btn btn-danger" role="delete" nid="{{ row.id }}" style="padding: 5px 10px; font-size:10px">删除</button></td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
    {% include 'include/common/delete_confirm_modal.html' %}
    {% include 'include/common/built_in_error_msg_modal.html' %}
{% endblock %}

{% block custome_js %}
    <script>
        $(function () {
            $('[role="delete"]').click(function () {
                 $('#delete_confirm_btn').attr('nid',$(this).attr('nid'));
                 $('#delete_confirm_modal').modal();
            });
            $('#delete_confirm_btn').click(function () {
                var nid = $(this).attr('nid');
                $.ajax({
                    url : "{% url 'obj_delete' 'Project' %}",
                    type: 'POST',
                    data: {'nid':nid},
                    dataType: 'JSON',
                    success: function (res) {
                        if(res.status){
                            $('tr[nid="'+nid+'"]').remove();
                        }else{
                            $('#built_in_error_msg_modal').modal();
                        }
                    },
                    error: function (res) {
                        $('#built_in_error_msg_modal').modal();
                    }
                });
            });
        });
    </script>
{% endblock %}